package top.wshape1.shiziapi.common.utils;

import java.util.Random;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-08-26
 */

public class RandomCodeUtil {
    private static final String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    /**
     * 生成6位的数字验证码
     *
     * @return
     */
    public static String generateNumCode() {
        Random random = new Random(System.currentTimeMillis());
        int i = random.nextInt(100001, 999999);
        return String.valueOf(i);
    }

    /**
     * 生成一段18位的数字字母混合验证码
     *
     * @return
     */
    public static String generateComplexCode() {
        StringBuilder stringBuilder = new StringBuilder();
        int num;
        Random random = new Random(System.currentTimeMillis());
        for (int i = 0; i < 18; i++) {
            num = random.nextInt(62);
            stringBuilder.append(str.charAt(num));
        }
        return stringBuilder.toString();
    }

}
